<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			.mui-input-group label {
				width: 22%;
			}
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.mui-btn {
				padding: 10px;
			}
			
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content">

			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名</label>
					<input id='name' type="text" class="mui-input-clear mui-input" placeholder="用户名">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>确认</label>
					<input id='password2' type="password" class="mui-input-clear mui-input" placeholder="请确认密码">
				</div>
				<div class="mui-input-row">
					<label>邮箱</label>
					<input id='email' type="email" class="mui-input-clear mui-input" placeholder="请输入邮箱">
				</div>
			</form>
			<div class="mui-content-padded">
				<button id='reg' class="mui-btn mui-btn-block mui-btn-primary">注册</button>
			</div>
			<div class="mui-content-padded">
				<p>注册真实可用，注册成功后的用户可用于登录，但是示例程序并未和服务端交互，用户相关数据仅存储于本地。</p>
			</div>
			<p id="err" style="width:60vw; height: 50px; border: 2px solid red; margin-top: 10vw; margin-left: 20vw; line-height: 50px; color: #DD524D; font-size: 1em;text-align: center;">请完成你的注册信息</p>
			
		</div> 
		
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script>
			mui.init();
     		mui.plusReady(function(){
            var name = document.getElementById("name");
            var email = document.getElementById("email");
             var password=document.getElementById("password");
            var password2 = document.getElementById("password2");
            var reg = document.getElementById('reg');
            var  err = document.getElementById('err');
            reg.addEventListener('tap',function(){
            	
            
             mui.ajax('http://www.zhangjianxiong.club:5000/api/users/register',{
				data:{                                        
				name:name.value,
				email:email.value,
				password:password.value,
				password2:password2.value
			},
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			timeout:10000,//超时时间设置为10秒；
			headers:{'Content-Type':'application/x-www-form-urlencoded'},	              
			success:function(data){
				if(data.name.length > 0)
				{
					alert(data.date);
					mui.openWindow({
						url:"login.html",
						id:"login"
					})
				}
			},
			error:function(xhr,type,errorThrown){
				var a = JSON.parse(xhr.response);
				if(a.email != undefined){
					err.innerHTML = a.email;
				}else if(a.password != undefined){
					err.innerHTML = a.password;
				}else if(a.password2 != undefined){
					err.innerHTML = a.password2;
				}else if(a.name != undefined){
					err.innerHTML = a.name;
				}

			}
		});
                
            })

        });
		</script>
	</body>

</html>



   